package com.wzj.yygh.hosp.controller.admin;

import com.wzj.yygh.common.result.R;
import com.wzj.yygh.hosp.service.HospitalService;
import com.wzj.yygh.model.hosp.Hospital;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author wzj
 */
@Api(tags = "医院接口")
@RestController
@RequestMapping("/admin/hosp/hospital")
//@CrossOrigin
public class AdminHospitalController {
    @Autowired
    private HospitalService hospitalService;

    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public R pageList(@PathVariable Integer page,@PathVariable Integer limit,String hosname){
        Page<Hospital> pageModel = hospitalService.selectHospPage(page, limit, hosname);
        return R.ok().data("pageModel",pageModel);
    }

    @ApiOperation(value = "更新上线状态")
    @GetMapping("updateStatus/{id}/{status}")
    public R lock(@PathVariable String id,@PathVariable Integer status){
        if (status != 0 && status != 1){
            return R.error().message("非法数据");
        }
        hospitalService.updateStatus(id,status);
        return R.ok();
    }
    @ApiOperation(value = "获取医院详情")
    @GetMapping("show/{id}")
    public R show(@PathVariable String id){
        Hospital hospital = hospitalService.getHospById(id);
        return R.ok().data("hospital",hospital);
    }
}
